﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using Register.Model;
using Register.DALFactory;
using Register.Command;

namespace Register.BLL
{
    /// <summary>
    /// FileName: AnnouncementBLL.cs
    /// CLRVersion: 4.0.30319.269
    /// Author: WangKunLun
    /// Corporation: 
    /// Description: 
    /// DateTime: 2012/6/30 23:11:24
    /// </summary>
    public class AnnouncementBLL
    {
        private static String typeNameKey = "IAnnouncementDALKey";

        public static bool AddAnnouncement(Model.Announcement model)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);
            try
            {
                if (iAnnouncement.AddAnnouncement(model) > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }

        public static bool DeleteAnnouncement(string AnnouncementID)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);
            try
            {
                if (iAnnouncement.DeleteAnnouncement(AnnouncementID) > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }

        public static bool UpdateAnnouncement(Model.Announcement model)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);
            try
            {
                if (iAnnouncement.UpdateAnnouncement(model) > 0)
                {
                    return true;
                }
                else
                    return false;
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }

        public static bool Exists(string Announcement_Title)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);

            try
            {
                return iAnnouncement.Exists(Announcement_Title);
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }

        public static List<Model.Announcement> GetPagedAnnouncement(int size, int pageIndex, string where)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);

            try
            {
                return iAnnouncement.GetPagedAnnouncement(size, pageIndex, where);
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }

        public static Model.Announcement GetAnnouncement(string AnnouncementID)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);
            try
            {
                return iAnnouncement.GetAnnouncement(AnnouncementID);
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }

        public static int GetAnnouncementCount(string where)
        {
            IAnnouncementDAL iAnnouncement = DALFactory<IAnnouncementDAL>.Create(typeNameKey);

            try
            {
                return iAnnouncement.GetAnnouncementCount(where);
            }
            catch (Exception e)
            {
                LogRecordHelper.LogNote("ERROR", e.Message);
                throw e;
            }
        }
    }
}
